package com.ucarbon.ucarbon.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ucarbon.ucarbon.service.ICountryService;
import com.ucarbon.ucarbon.service.IYearCountryNppService;
import com.ucarbon.ucarbon.service.IYearsService;
import com.ucarbon.ucarbon.utils.RespBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;


/**
 * <p>
 * 区县, 年份对应NPP的表格 前端控制器
 * </p>
 *
 * @author XuGaoran
 * @since 2024-01-04
 */
@RestController
@RequestMapping("/ucarbon/yearCountryNpp")
public class YearCountryNppController {

    @Autowired
    private IYearCountryNppService yearCountryNppService;

    @Autowired
    private IYearsService yearsService;

    @Autowired
    private ICountryService countryService;

    @GetMapping("/querybyyear")
    public RespBean queryByYear(@RequestParam Integer year) {
        Boolean hasYear = yearsService.hasYear(year);
        if (!hasYear.booleanValue()) {
            return RespBean.error("没有当前年份数据!");
        }
        return yearCountryNppService.selectByYear(year);
    }

    @GetMapping("/querybycountry")
    public RespBean queryByYear(@RequestParam String country) {
        Boolean hasCountry = countryService.hasCountry(country);
        if (!hasCountry.booleanValue()) {
            return RespBean.error("没有当前城市数据!");
        }
        return yearCountryNppService.selectByCountry(country);
    }

    @GetMapping("/queryvalue")
    public RespBean queryMaxNpp(@RequestParam String country, @RequestParam Integer year) {
        Boolean hasYear = yearsService.hasYear(year);
        Boolean hasCountry = countryService.hasCountry(country);
        if ((!hasYear.booleanValue()) || (!hasCountry.booleanValue())) {
            return RespBean.error("没有当前年份/城市数据!");
        }
        return yearCountryNppService.selectFuncValue(country, year);
    }
    
}
